package cn.school.thoughtworks.section1;

import java.util.ArrayList;

import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class PracticeA {
    List<String> collectSameElements(List<String> collection1, List<String> collection2) {
        //实现练习要求，并改写该行代码。
//        List<String>  collection3 = new ArrayList<String>();
//        HashSet<String> hashSet = new HashSet<String>();
//
//        for (String s :  collection2) {
//            hashSet.add(s);
//        }
//        for (String s :  collection1) {
//            if(hashSet.add(s)==false){
//                collection3.add(s);
//            }
//        }
//
//
//        return  collection3;
        List collection = new ArrayList(collection1);
        collection.retainAll(collection2);
        return  collection;


    }
}
